package com.itshizhan.designpattern.abstract_factory;

import com.itshizhan.designpattern.abstract_factory.factory.Factory;
import com.itshizhan.designpattern.abstract_factory.factory.Link;
import com.itshizhan.designpattern.abstract_factory.factory.Page;
import com.itshizhan.designpattern.abstract_factory.factory.Tray;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        System.out.println("args = " + Arrays.deepToString(args));
        if (args.length!=1){
            System.out.println("Usage:java Main class.name of ConcreteFactory");
            System.out.println("Example 1: java Main Listfactory.ListFactory");
            System.out.println("Example 2: java Main tablefactory.TableFactory");
            System.exit(0);
        }
        Factory factory = Factory.getFactory(args[0]);
        Link people = factory.createLink("人民日报","https://www.people.com.cn");
        Link gmw = factory.createLink("光明日报","https://www.gmw.cn");
        Link us_yahoo = factory.createLink("yahoo","https://www.yahoo.com");
        Link jp_yahoo = factory.createLink("Yahoo,Japan","https://www.yahoo.com/jp");
        Link excite = factory.createLink("Excite","https://www.excite.com");
        Link google = factory.createLink("Google","https://www.google.com");

        Tray trayNews = factory.createTray("日报");
        trayNews.add(people);
        trayNews.add(gmw);

        Tray trayYahoo = factory.createTray("Yahoo!");
        trayYahoo.add(us_yahoo);
        trayYahoo.add(jp_yahoo);

        Tray traySearch = factory.createTray("检索引擎");
        traySearch.add(traySearch);
        trayNews.add(excite);
        trayNews.add(google);

        Page page = factory.createPage("LinkPage","杨文轩");
        page.add(trayNews);
        page.add(traySearch);
        page.output();

    }
}
